﻿using System;
using System.Collections.Generic;
using System.Text;
using com.lover.astd.common.logic;
using com.lover.astd.common.model.enumer;

namespace com.lover.astd.common.logicexe.activities
{
    public class CrossplatformCompeteExe : ExeBase
    {
        public CrossplatformCompeteExe() { _name = ConfigStrings.S_CrossPlatform_Compete; _readable = ConfigStrings.SR_CrossPlatform_Compete; }
        public override long execute()
        {
            Dictionary<string, string> conf = getConfig();
            if (!conf.ContainsKey(ConfigStrings.enabled) || !conf[ConfigStrings.enabled].ToLower().Equals("true")) return an_hour_later();
            if (!_user.isActivityRunning(ActivityType.CrossplatformCompete)) return next_hour();
            int support_gold = 0;
            if (conf.ContainsKey(ConfigStrings.support_gold)) Int32.TryParse(conf[ConfigStrings.support_gold], out support_gold);

            ActivityMgr mgr = ServiceFactory.getActivityManager();
            long cdMseconds = 0;
            int result = mgr.handleCrossPlatformCompeteInfo(_proto, _logger, getGoldAvailable(), support_gold, out cdMseconds);
            if (result != 0) return next_hour();
            else
            {
                if (cdMseconds > 0) return cdMseconds;
                else return immediate();
            }
        }
    }
}
